package com.zsl.swing.redis.desktop.window.menu;

import com.zsl.swing.redis.desktop.type.MainMenuEnum;
import com.zsl.swing.redis.desktop.window.ZslRedisDesktopMainWindow;
import com.zsl.swing.redis.desktop.window.dialog.ZslCollectionDialog;
import com.zsl.swing.redis.desktop.window.help.ZslRedisCmdHelpWindow;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

public class ZslOtherMenu extends ZslMenu implements ActionListener {

    private static final String ISSUES_SITE = "https://gitee.com/zhangsan_zsl/RedisDesktop/issues";

    public ZslOtherMenu() {
        super(MainMenuEnum.OTHER.getText());

        this.add(ZslMenuItem.getInstance(MainMenuEnum.REDIS_COMMAND.getText(),this));
        this.add(ZslMenuItem.getInstance(MainMenuEnum.FEEDBACK.getText(), this));
        this.add(ZslMenuItem.getInstance(MainMenuEnum.REWARD.getText(), this));


    }

    @Override
    public void actionPerformed(ActionEvent e) {
        String command = e.getActionCommand();
        if(MainMenuEnum.REWARD.getText().equals(command)){
            ZslCollectionDialog.showDialog();
        }else if(MainMenuEnum.REDIS_COMMAND.getText().equals(command)){
            ZslRedisCmdHelpWindow.showHelpDialog();
        }else if(MainMenuEnum.FEEDBACK.getText().equals(command)){
            try {
                Desktop.getDesktop().browse(new URI(ISSUES_SITE));
            } catch (IOException | URISyntaxException ex) {
                ZslRedisDesktopMainWindow.getZslLogPanel().logError(ex);
            }
        }



    }
}
